﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLayer;
using System.Configuration;
using DTO;
using System.Data;

namespace ABCComputer.DAL
{
    public class HinhAnhDAL
    {
        private DBManager dbmanager;
        public HinhAnhDAL()
        {
            string ConnectionInfo = ConfigurationManager.AppSettings["ConnectionInfo"];
            dbmanager = new DBManager(DataProvider.SqlServer, ConnectionInfo);
        }

        // lay danh sach hinh anh 1 san pham
        public List<HinhAnhDTO> getListHinhAnhMotSanPham(string masanpham)
        {

            List<HinhAnhDTO> lstHA = new List<HinhAnhDTO>();
            IDataReader readerHA = null;
            try
            {
                dbmanager.Open();
                dbmanager.CreateParameters(1);
                dbmanager.AddParameters(0, "@masanpham", masanpham);
                readerHA = dbmanager.ExecuteReader(CommandType.StoredProcedure, "usp_getListHinhAnhMotSanPHam");

                while (readerHA.Read())
                {
                    HinhAnhDTO ha = new HinhAnhDTO();
                    ha.MaHinhAnh = (int)readerHA["mahinhanh"];
                    ha.TenHinhAnh = Convert.ToString(readerHA["tenhinhanh"]);
                    lstHA.Add(ha);
                }

            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            finally
            {
                readerHA.Close();
            }
            return lstHA;
        }
    }
}